<template>
  <div class="app-container">
    <IncreServiceFeeDetailEdit ref="openIncreServiceFeeDetailEdit"  @refresh="refresh"></IncreServiceFeeDetailEdit>
    <div class="detail-title-box">
      <span>详情信息</span>
    </div>
    <el-form @submit.native.prevent :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" :label-position="labelPosition" label-width="120">
      <el-form-item label="柜号/批号" prop="spgh">
        <el-input
          v-model="queryParams.spgh"
          placeholder="请输入柜号/批号"
          clearable
          @keyup.enter.native="enterClick"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="getList">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="increServiceFeeDetail"
      show-summary
      :summary-method="getSummaries"
    >
      <af-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100" fixed="left">
        <template slot-scope="scope">
            <el-button
                size="mini"
                type="text"
                @click="handleEdit(scope.row)"
                v-hasPermi="['zhcloud:zzfwf:modify']"
            >修改</el-button>
            <el-button
                size="mini"
                type="text"
                @click="handleDelete(scope.row)"
                v-hasPermi="['zhcloud:zzfwf:del']"
            >删除</el-button>
        </template>
      </af-table-column>
      <af-table-column label="收费项目" align="center" prop="xm" />
      <af-table-column label="收费单价" align="center" prop="bzdj" />
      <af-table-column label="收费标准" align="center" prop="bz" />
      <af-table-column label="吨数" align="center" prop="spsl" />
      <af-table-column label="金额" align="center" prop="sfje" />
      <af-table-column label="发生日期" align="center" prop="rqid" />
      <af-table-column label="物品规格" align="center" prop="spzs" />
      <af-table-column label="柜号" align="center" prop="spgh" />
      <af-table-column label="批号" align="center" prop="spbh" />
      <af-table-column label="仓库" align="center" prop="spckmc" />
      <af-table-column label="客户" align="center" prop="allName" />
      <af-table-column label="客户条码" align="center" prop="sptm" />
      <af-table-column label="仓库条码" align="center" prop="sptmc" />
      <af-table-column label="入仓日期" align="center" prop="ssrqid" />
      <af-table-column label="备注" align="center" prop="itbz"   width="150" :show-overflow-tooltip="true"/>
    </el-table>
    <el-row type="flex" justify="center" :gutter="5" class="mt20">
      <el-col :span="1.5">
        <el-button @click="goBack">返回</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { getIncreServiceFeeDetail, increServiceFeeItemDel } from "@/api/storage/commonGoods/increServiceFee";
import IncreServiceFeeDetailEdit from './increServiceFeeDetailEdit.vue'
import { AMOUNT_DIGIT, WEIGHT_DIGIT } from '@/utils/constant'

export default {
  name: "IncreServiceFeeDetail",
  components:{IncreServiceFeeDetailEdit},
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      //对齐方式
      labelPosition:"right",
      //列表加载
      loading: true,
      //发生时间
      happenDate:'',
      // 查询参数
      queryParams: {
        khmc: "",
        pzbh: "",
        rqid1: "",
        rqid2: "",
        spgh: "",
        xm: ""
      },
      delelteParams: {
        bz: "",
        bzdj: "",
        id: 0,
        itbz: "",
        rqid: "",
        spje: "",
        spsl: "",
        xm: ""
      },
      //增值服务收费明细数据
      increServiceFeeDetail:[],
      //批量审核数据
      selection:[],
      //页数
      pageSize: 999,
      //页码
      pageNum:1,
      // 总条数
      total: 0,
    };
  },
  beforeRouteEnter(to, from, next) {
    const query = to.query
    next(vm => {   
      if(Object.keys(query).length > 0) {
        vm.reset(vm)
        vm.queryParams.pzbh = query.pzbh
        vm.getList()
      }
    })
  },
  methods: {
    /** 查询增值服务收费列表 */
    getList() {
      this.loading=true
      getIncreServiceFeeDetail(this.queryParams, {pageNum:this.pageNum, pageSize:this.pageSize}).then(response => {
        this.increServiceFeeDetail = response.rows;
        this.total = response.total;
        this.loading=false
      });
    },
    /**删除 */
    deleteIncreServiceFeeItemDel() {
      this.$modal.loading("数据正在删除中，请稍等...")
      increServiceFeeItemDel(this.delelteParams).then(response => {
        this.$modal.closeLoading()
        this.$modal.msgSuccess('删除成功！')
        this.getList()
      }).catch(()=> {
        this.$modal.closeLoading()
      })
    },
    /**编辑 */
    handleEdit(data) {
      this.$refs.openIncreServiceFeeDetailEdit.open(data)
    },
    handleDelete(row) {
      const {bz= "",bzdj= "",id= 0,itbz= "",rqid= "",spje= "",spsl= "",xm= ""} = row
      this.delelteParams = {bz,bzdj,id,itbz,rqid,spje,spsl,xm}
      this.$modal.confirm("是否删除记录？").then(() => {
        this.deleteIncreServiceFeeItemDel()
      }).catch(() => {})
    },
    //合计
    getSummaries({ columns, data }) {
      const sums = []
      columns.forEach((column, index) => {
        if(index === 0) {
          sums[index] = "合计"
			    return
        }
        if ((column.property === "spsl" || column.property === "sfje")) {
          const values = data.map((item) => {
            return parseFloat(this.delcommafy(item[column.property]))
          });
          sums[index] = values.reduce((prev, curr) => {
            if(!prev) prev = 0
            if(!curr) curr = 0
            if(column.property === "spsl") {
              return parseFloat((prev + curr).toFixed(WEIGHT_DIGIT))
            }
             if(column.property === "sfje") {
              return parseFloat((prev + curr).toFixed(AMOUNT_DIGIT))
            }
          }, 0);
        }
      })
      return sums
    },
    refresh() {
      this.getList()
    },
     /**enter键触发 */
    enterClick(e) {
      this.getList()
    },
     /** 重置数据 */
    reset(vm) {
      Object.assign(vm.$data, vm.$options.data())
    },
      /**返回不刷新 */
    goBack() {
      this.$router.push({name:"IncreServiceFee"})
    }
  }
};
</script>
